//对当前点击对象(通道号按钮)更换css样式
$(document).ready(function(){


    $('#start').blur(function(){
        let start= $('#start').val();
        let end = $('#end').val();
        if(start=="" || end==""){
            
            $('#tips').text("查询地址不能为空")
        }else{
            $('#tips').text("")
            $.ajax({
           
                type: "POST",
                dataType: "json",
                url: url + "/page/selectByArea" ,//url
                data: {
                    start:start,
                    end:end
                },
                success: function (result) {
                    console.log(result);//打印服务端返回的数据(调试用)
                    if (result.code == 1) {
                       
                        console.log(result.data.firstPrice)
                        console.log(result.data.continuation)
                        $('#first').text(result.data.firstPrice);
                        $('#finally').text(result.data.continuation);
                    }else if(result.code == 2){
                        $('#tips').text("无效的地址")
                        $('#first').text("-");
                        $('#finally').text("-");
                    }
                    
                },
                error : function() {
                    layer.msg("网络繁忙,请稍后再试");
                }
            });
        }
    })

    $('#end').blur(function(){
        let start = $('#start').val();
        let end = $('#end').val();
        if(start=="" || end==""){
            
            $('#tips').text("查询地址不能为空")
        }else{
            $('#tips').text("")
            $.ajax({
           
                type: "POST",
                dataType: "json",
                url: url + "/page/selectByArea" ,//url
                data: {
                    start:start,
                    end:end
                },
                success: function (result) {
                    console.log(result);//打印服务端返回的数据(调试用)
                    if (result.code == 1) {
                       
                        console.log(result.data.firstPrice)
                        console.log(result.data.continuation)
                        $('#first').text(result.data.firstPrice);
                        $('#finally').text(result.data.continuation);
                    }else if(result.code == 2){
                        $('#tips').text("无效的地址")
                        $('#first').text("-");
                        $('#finally').text("-");
                    }
                    
                },
                error : function() {
                    layer.msg("网络繁忙,请稍后再试");
                }
            });

        }
    })

    $('#info .prompt').click(function(){
        if($(this).hasClass("new")){
             $(this).removeClass("new");
            $(this).addClass("prompt");
        }
       
        else{
            $(this).removeClass("prompt");
            $(this).addClass("new");
        }     
    })

    $('#bt .href').click(function(){
        window.location.href="bulk-delivery.html";
    })

    $('.member button').click(function(){
        window.location.href="login-head.html";
    })


    $('.checkbox #label-a').click(function(){
        if($(this).hasClass("label-check")){
             $(this).removeClass("label-check");
             $(this).addClass("label-a");
             $(".checkbox-a").prop("checked", false);
            
        }
       
        else{
            $(this).removeClass("label-a");
            $(this).addClass("label-check");
            $(".checkbox-a").prop("checked", true);
        }     
    })


    $('#check-b #label-b').click(function(){
        if($(this).hasClass("label-check")){
             $(this).removeClass("label-check");
             $(this).addClass("label-b");
             $(".checkbox-b").prop("checked", false);
            
        }
       
        else{
            $(this).removeClass("label-b");
            $(this).addClass("label-check");
            $(".checkbox-b").prop("checked", true);
        }     
    })


    $('.agreement .left label').click(function(){
        if($(this).hasClass("agree")){
             $(this).removeClass("agree");
           
             $(".checkbox-agree").prop("checked", false);
            
        }
       
        else{
         
            $(this).addClass("agree");
            $(".checkbox-agree").prop("checked", true);
        }     
    })

    $('.information .one').click(function(){
        $("#other").attr("checked",false);
        if($("#other").is(':checked') == true){
            $('.bt-in').removeAttr('disabled') 
            $('.top').removeAttr('disabled')
            $('.bottom').removeAttr('disabled')
        }else{
           
            $('.bt-in').attr('disabled',true) 
            $('.top').attr('disabled',true)
            $('.bottom').attr('disabled',true)
        }

        // if($(this).hasClass("agree")){
        //      $(this).removeClass("agree");
           
        //      $("#one").prop("checked", false);
            
        // }
       
        // else{
            $('.two').removeClass("agree");
            $('.other').removeClass("agree");
            $('.three').removeClass("agree");
            $(this).addClass("agree");
            $("#one").prop("checked", true);
        // }     
    })

    $('.information .two').click(function(){
        $("#other").attr("checked",false);
        if($("#other").is(':checked') == true){
            $('.bt-in').removeAttr('disabled') 
            $('.top').removeAttr('disabled')
            $('.bottom').removeAttr('disabled')
        }else{
           
            $('.bt-in').attr('disabled',true) 
            $('.top').attr('disabled',true)
            $('.bottom').attr('disabled',true)
        }

        // if($(this).hasClass("agree")){
        //      $(this).removeClass("agree");
           
        //      $("#two").prop("checked", false);
            
        // }
       
        // else{
           $('.one').removeClass("agree");
           $('.other').removeClass("agree");
             $('.three').removeClass("agree");
            $(this).addClass("agree");
            $("#two").prop("checked", true);
        //}     
    })

    $('.information .three').click(function(){
        $("#other").attr("checked",false);
        if($("#other").is(':checked') == true){
            $('.bt-in').removeAttr('disabled') 
            $('.top').removeAttr('disabled')
            $('.bottom').removeAttr('disabled')
        }else{
           
            $('.bt-in').attr('disabled',true) 
            $('.top').attr('disabled',true)
            $('.bottom').attr('disabled',true)
        }

        // if($(this).hasClass("agree")){
        //      $(this).removeClass("agree");
           
        //      $("#three").prop("checked", false);
            
        // }
       
        // else{
          $('.two').removeClass("agree");
             $('.one').removeClass("agree");
             $('.other').removeClass("agree");
            $(this).addClass("agree");
            $("#three").prop("checked", true);
        //}     
    })

    $('.information .other').click(function(){
        // if($(this).hasClass("agree")){
        //      $(this).removeClass("agree");
           
        //      $("#other").prop("checked", false);
            
        // }
       
        // else{
            $('.two').removeClass("agree");
            $('.one').removeClass("agree");
            $('.three').removeClass("agree");
            $(this).addClass("agree");
            $("#other").prop("checked", true);
        //}     
    })

    $('.checkbox-agree').click(function(){
        if($(".checkbox-agree").is(':checked') == true){
            $('.agree-label').addClass("agree");
        }else{
            $('.agree-label').removeClass("agree");
        }
    })

    $('.checkbox-a').click(function(){
        if($(".checkbox-a").is(':checked') == true){
            $('#label-a').removeClass("label-a");
            $('#label-a').addClass("label-check");
        }else{
            $('#label-a').removeClass("label-check");
            $('#label-a').addClass("label-a");
        }
    })

    $('.checkbox-b').click(function(){
        if($(".checkbox-b").is(':checked') == true){
            $('#label-b').addClass("label-check");
            $('#label-b').removeClass("label-b");
        }else{
            $('#label-b').removeClass("label-check");
            $('#label-b').addClass("label-b");
        }
    })
    var b = 1;
    $('.other').click(function(){
        if($("#other").is(':checked') == true){
            $(".bt-in").val(b);
            $('.bt-in').removeAttr('disabled') 
            $('.top').removeAttr('disabled')
            $('.bottom').removeAttr('disabled')
        }else{
           
            $('.bt-in').attr('disabled',true) 
            $('.top').attr('disabled',true)
            $('.bottom').attr('disabled',true)
        }
    })
        
   
    $("#bt-add").click(function(){
        if(b<30){
            b++;
            $(".bt-in").val(b);
        }
            
        
    });

    $("#bt-sub").click(function(){
        if(b>1){
            b--;
            $(".bt-in").val(b);
        }
    });


    $("*").click(function(){



        if($("#other").is(':checked') == true){


            $('.information .other').addClass("agree");

            $(".bt-in").val(b);
            $('.bt-in').removeAttr('disabled') 
            $('.top').removeAttr('disabled')
            $('.bottom').removeAttr('disabled')
        }else{
            b = 1;
            $(".bt-in").val("");
            $('.bt-in').attr('disabled',true) 
            $('.top').attr('disabled',true)
            $('.bottom').attr('disabled',true)
             $('.information .other').removeClass("agree");
        }

        if($("#one").is(':checked') == true){
            $('.information .one').addClass("agree");
        }else{
            $('.information .one').removeClass("agree");
        }

        if($("#three").is(':checked') == true){
            $('.information .three').addClass("agree");
        }else{
            $('.information .three').removeClass("agree");
        }

        if($("#two").is(':checked') == true){
            $('.information .two').addClass("agree");
        }else{
            $('.information .two').removeClass("agree");
        }




    });

    $('#info .prompt').click(function(){
        if($(this).hasClass("new")){
            $(this).find('input').attr('name','remarksTip');
        }

        else{
            $(this).find('input').attr('name','a');
        }
    })

    $(".middle-regulations .button").click(function(){
       
    });

});




$(function(){

    $("#send-phone-text").blur(function(){
        
        let phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
        let sendPhone = $.trim($('#send-phone-text').val());
        if (sendPhone=="") {
            // layer.msg("请输入有效的手机号码");
            $('#send-phone-text').css({border:"solid 1px red"});
            $('#send-phone-p').html("手机号不能为空");
        }else{
            if (!phoneReg.test(sendPhone)) {
                $('#send-phone-text').css({border:"solid 1px blue"});
                $('#send-phone-p').html("");
                $('#send-phone-text').css({border:"solid 1px red"});
                $('#send-phone-p').html("请输入正确的手机号");
            }else{
                $('#send-phone-text').css({border:"solid 1px #67C23A"});
                $('#send-phone-p').html("");
            }
        }   
    });

    $("#recevice-phone-text").blur(function(){
        let phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
        let recevicePhone = $.trim($('#recevice-phone-text').val());
        if (recevicePhone=="") {
            // layer.msg("请输入有效的手机号码");
            $('#recevice-phone-text').css({border:"solid 1px red"});
            $('#recevice-phone-p').html("手机号不能为空");
        }else{
            if (!phoneReg.test(recevicePhone)) {
                $('#recevice-phone-text').css({border:"solid 1px blue"});
                $('#recevice-phone-p').html("");
                $('#recevice-phone-text').css({border:"solid 1px red"});
                $('#recevice-phone-p').html("请输入正确的手机号");
            }else{
                $('#recevice-phone-text').css({border:"solid 1px #67C23A"});
                $('#recevice-phone-p').html("");
            }
        }   
    });

    $("#send-name-text").blur(function(){
        let sendName = $.trim($('#send-name-text').val());
        if (sendName=="") {
            $('#send-name-text').css({border:"solid 1px red"});
            $('#send-name-p').html("寄件人姓名不能为空");
           
        }else{
            $('#send-name-text').css({border:"solid 1px #67C23A"});
            $('#send-name-p').html("");
            
             
        }   
    });

    $("#send-area-text").blur(function(){
        let sendArea = $.trim($('#send-area-text').val());
        if (sendArea=="") {
            $('#send-area-text').css({border:"solid 1px red"});
            $('#send-area-p').html("请输入所属区域");
           
        }else{
            $('#send-area-text').css({border:"solid 1px #67C23A"});
            $('#send-area-p').html("");
            
             
        }   
    });

    $("#send-address-text").blur(function(){
        let sendAddress = $.trim($('#send-address-text').val());
        if (sendAddress=="") {
            $('#send-address-text').css({border:"solid 1px red"});
            $('#send-address-p').html("请输入详细地址");
           
        }else{
            $('#send-address-text').css({border:"solid 1px #67C23A"});
            $('#send-address-p').html("");
            
             
        }   
    });

    $("#recevice-name-text").blur(function(){
        let receviceName = $.trim($('#recevice-name-text').val());
        if (receviceName=="") {
            $('#recevice-name-text').css({border:"solid 1px red"});
            $('#recevice-name-p').html("收件人姓名不能为空");
           
        }else{
            $('#recevice-name-text').css({border:"solid 1px #67C23A"});
            $('#recevice-name-p').html("");
            
             
        }   
    });

    $("#recevice-area-text").blur(function(){
        let receviceArea = $.trim($('#recevice-area-text').val());
        if (receviceArea=="") {
            $('#recevice-area-text').css({border:"solid 1px red"});
            $('#recevice-area-p').html("请输入所属区域");
           
        }else{
            $('#recevice-area-text').css({border:"solid 1px #67C23A"});
            $('#recevice-area-p').html("");
            
             
        }   
    });

    $("#recevice-address-text").blur(function(){
        let receviceAddress = $.trim($('#recevice-address-text').val());
        if (receviceAddress=="") {
            $('#recevice-address-text').css({border:"solid 1px red"});
            $('#recevice-address-p').html("请输入详细地址");
           
        }else{
            $('#recevice-address-text').css({border:"solid 1px #67C23A"});
            $('#recevice-address-p').html("");
            
             
        }   
    });

    $("#form").submit(function(){

        if(!$(".checkbox-agree").prop("checked")){
            layer.msg("请先勾选协议");
            return false;
        }

        let flag = 0;
        let phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
        let sendPhone = $.trim($('#send-phone-text').val());
        if (sendPhone=="") {
            // layer.msg("请输入有效的手机号码");
            $('#send-phone-text').css({border:"solid 1px red"});
            $('#send-phone-p').html("手机号不能为空");
            flag = 1;
        }else{
            if (!phoneReg.test(sendPhone)) {
                $('#send-phone-text').css({border:"solid 1px blue"});
                $('#send-phone-p').html("");
                $('#send-phone-text').css({border:"solid 1px red"});
                $('#send-phone-p').html("请输入正确的手机号");
                flag = 1;
            }else{
                $('#send-phone-text').css({border:"solid 1px #67C23A"});
                $('#send-phone-p').html("");
            }
        }   

        let recevicePhone = $.trim($('#recevice-phone-text').val());
        if (recevicePhone=="") {
            // layer.msg("请输入有效的手机号码");
            $('#recevice-phone-text').css({border:"solid 1px red"});
            $('#recevice-phone-p').html("手机号不能为空");
            flag = 1;
        }else{
            if (!phoneReg.test(recevicePhone)) {
                $('#recevice-phone-text').css({border:"solid 1px blue"});
                $('#recevice-phone-p').html("");
                $('#recevice-phone-text').css({border:"solid 1px red"});
                $('#recevice-phone-p').html("请输入正确的手机号");
                flag = 1;
            }else{
                $('#recevice-phone-text').css({border:"solid 1px #67C23A"});
                $('#recevice-phone-p').html("");
            }
        }   

        let sendName = $.trim($('#send-name-text').val());
        if (sendName=="") {
            $('#send-name-text').css({border:"solid 1px red"});
            $('#send-name-p').html("寄件人姓名不能为空");
            flag = 1;
            
        }else{
            $('#send-name-text').css({border:"solid 1px #67C23A"});
            $('#send-name-p').html("");
            
                
        }   

        // let sendArea = $.trim($('#send-area-text').val());
        // if (sendArea=="") {
        //     $('#send-area-text').css({border:"solid 1px red"});
        //     $('#send-area-p').html("请输入所属区域");
        //     flag = 1;
            
        // }else{
        //     $('#send-area-text').css({border:"solid 1px #67C23A"});
        //     $('#send-area-p').html("");
            
                
        // }   

        let sendAddress = $.trim($('#send-address-text').val());
        if (sendAddress=="") {
            $('#send-address-text').css({border:"solid 1px red"});
            $('#send-address-p').html("请输入详细地址");
            flag = 1;
            
        }else{
            $('#send-address-text').css({border:"solid 1px #67C23A"});
            $('#send-address-p').html("");
            
                
        }   

        let receviceName = $.trim($('#recevice-name-text').val());
        if (receviceName=="") {
            $('#recevice-name-text').css({border:"solid 1px red"});
            $('#recevice-name-p').html("收件人姓名不能为空");
            flag = 1;
            
        }else{
            $('#recevice-name-text').css({border:"solid 1px #67C23A"});
            $('#recevice-name-p').html("");
            
                
        }   

        // let receviceArea = $.trim($('#recevice-area-text').val());
        // if (receviceArea=="") {
        //     $('#recevice-area-text').css({border:"solid 1px red"});
        //     $('#recevice-area-p').html("请输入所属区域");
        //     flag = 1;
            
        // }else{
        //     $('#recevice-area-text').css({border:"solid 1px #67C23A"});
        //     $('#recevice-area-p').html("");
            
                
        // }   

        let receviceAddress = $.trim($('#recevice-address-text').val());
        if (receviceAddress=="") {
            $('#recevice-address-text').css({border:"solid 1px red"});
            $('#recevice-address-p').html("请输入详细地址");
            flag = 1;
            
        }else{
            $('#recevice-address-text').css({border:"solid 1px #67C23A"});
            $('#recevice-address-p').html("");
                        
        }
        if(flag == 1){
            return false;
        }else{
            $.ajax({
                //几个参数需要注意一下
                    type: "POST",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: url + "/user/addUserPage" ,//url
                    data: $('#form').serialize(),
                    success: function (result) {
                        console.log(result);//打印服务端返回的数据(调试用)
                        if (result.code == 1) {
                            layer.msg("预约成功，快递员将尽快与您联系")
                        }else if(result.code == 2){
                            layer.msg("网络繁忙,请稍后再试");
                        }
                        ;
                    },
                    error : function() {
                        layer.msg("网络繁忙,请稍后再试");
                    }
                });


            return false;
        }
    });


});
